<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>赛马问题 - 算法思维的艺术</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: 0.2rem;
            color: #667eea;
        }
        pre {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            font-size: 0.9rem;
            line-height: 1.6;
        }
        .code-keyword {
            color: #569cd6;
        }
        .code-string {
            color: #ce9178;
        }
        .code-comment {
            color: #6a9955;
        }
        .step-number {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            flex-shrink: 0;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">赛马问题</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">算法思维的艺术：如何用最少的比赛次数找出最快的三匹马</p>
            <div class="flex justify-center space-x-6 text-sm">
                <span><i class="fas fa-horse mr-2"></i>25匹马</span>
                <span><i class="fas fa-road mr-2"></i>5条赛道</span>
                <span><i class="fas fa-trophy mr-2"></i>找出前3名</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description Card -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
            <div class="flex items-start mb-6">
                <i class="fas fa-question-circle text-3xl text-purple-600 mr-4"></i>
                <div class="flex-1">
                    <h2 class="text-2xl font-bold mb-4 text-gray-800">问题描述</h2>
                    <p class="text-gray-600 leading-relaxed">
                        <span class="drop-cap serif-font">有</span>25匹马和5个赛道，每次最多只能赛5匹马，且没有计时器。请问最少需要多少次比赛，才能选出速度最快的前3匹马？这是一道经典的逻辑推理题，考察的是如何通过巧妙的分组和比较，用最少的步骤得出结果。
                    </p>
                </div>
            </div>
            
            <div class="grid md:grid-cols-3 gap-4 mt-8">
                <div class="bg-purple-50 rounded-lg p-4 text-center">
                    <i class="fas fa-brain text-2xl text-purple-600 mb-2"></i>
                    <h3 class="font-semibold text-gray-800">核心考点</h3>
                    <p class="text-sm text-gray-600 mt-1">分组、排序、逻辑推理</p>
                </div>
                <div class="bg-blue-50 rounded-lg p-4 text-center">
                    <i class="fas fa-clock text-2xl text-blue-600 mb-2"></i>
                    <h3 class="font-semibold text-gray-800">时间复杂度</h3>
                    <p class="text-sm text-gray-600 mt-1">O(1) 固定次数</p>
                </div>
                <div class="bg-green-50 rounded-lg p-4 text-center">
                    <i class="fas fa-memory text-2xl text-green-600 mb-2"></i>
                    <h3 class="font-semibold text-gray-800">空间复杂度</h3>
                    <p class="text-sm text-gray-600 mt-1">O(1)</p>
                </div>
            </div>
        </div>

        <!-- Solution Steps -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>
                解题思路
            </h2>
            
            <div class="space-y-6">
                <div class="flex items-start">
                    <div class="step-number">1</div>
                    <div class="ml-4 flex-1">
                        <h3 class="font-semibold text-lg mb-2">初始分组比赛</h3>
                        <p class="text-gray-600">将25匹马分成5组（A、B、C、D、E），每组5匹马，进行5场比赛。每组内部得出排名：A1>A2>A3>A4>A5，以此类推。</p>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">2</div>
                    <div class="ml-4 flex-1">
                        <h3 class="font-semibold text-lg mb-2">冠军争夺赛</h3>
                        <p class="text-gray-600">取每组第一名（A1、B1、C1、D1、E1）进行一场比赛，确定总冠军。假设结果为：A1>B1>C1>D1>E1。</p>
                    </div>
                </div>
                
                <div class="flex items-start">
                    <div class="step-number">3</div>
                    <div class="ml-4 flex-1">
                        <h3 class="font-semibold text-lg mb-2">确定亚军和季军</h3>
                        <p class="text-gray-600">通过逻辑分析，第二名可能是A2或B1，第三名可能是A3、B1、B2或C1。让A2、A3、B1、B2、C1再比赛一次，即可确定前三名。</p>
                    </div>
                </div>
            </div>
            
            <div class="mt-8 bg-gradient-to-r from-purple-100 to-blue-100 rounded-lg p-6">
                <p class="text-center text-lg font-semibold text-gray-800">
                    <i class="fas fa-flag-checkered mr-2"></i>
                    最少需要 <span class="text-3xl font-bold gradient-text">7</span> 次比赛
                </p>
            </div>
        </div>

        <!-- Visual Diagram -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-project-diagram text-blue-500 mr-3"></i>
                比赛流程图
            </h2>
            <div class="mermaid">
                graph TD
                    A[25匹马] --> B[分成5组]
                    B --> C1[A组比赛]
                    B --> C2[B组比赛]
                    B --> C3[C组比赛]
                    B --> C4[D组比赛]
                    B --> C5[E组比赛]
                    C1 --> D1[A1 A2 A3 A4 A5]
                    C2 --> D2[B1 B2 B3 B4 B5]
                    C3 --> D3[C1 C2 C3 C4 C5]
                    C4 --> D4[D1 D2 D3 D4 D5]
                    C5 --> D5[E1 E2 E3 E4 E5]
                    D1 --> E[各组第一名比赛]
                    D2 --> E
                    D3 --> E
                    D4 --> E
                    D5 --> E
                    E --> F[A1>B1>C1>D1>E1]
                    F --> G[A2 A3 B1 B2 C1比赛]
                    G --> H[确定前三名]
                    
                    style A fill:#667eea,stroke:#fff,color:#fff
                    style H fill:#764ba2,stroke:#fff,color:#fff
            </div>
        </div>

        <!-- Code Implementation -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-code text-green-500 mr-3"></i>
                示例代码
            </h2>
            <pre><code><span class="code-comment">/**
 * 赛马问题解决方案
 * 这是一个逻辑推理问题，代码主要用于展示解题思路
 */</span>
<span class="code-keyword">public class</span> HorseRacing {
    <span class="code-comment">/**
     * 求解赛马问题
     * @return 最少需要的比赛次数
     */</span>
    <span class="code-keyword">public int</span> minRaces() {
        <span class="code-comment">// 步骤1: 将25匹马分成5组进行比赛，每组5匹马</span>
        <span class="code-comment">// 这一步需要5次比赛</span>
        <span class="code-keyword">int</span> races = 5;
        
        <span class="code-comment">// 步骤2: 让每组的第一名进行一次比赛，确定最快的马</span>
        <span class="code-comment">// 这一步需要1次比赛</span>
        races += 1;
        
        <span class="code-comment">// 步骤3: 根据第二步比赛结果，再进行必要的比赛确定第二名和第三名</span>
        <span class="code-comment">// 这一步需要1次比赛</span>
        races += 1;
        
        <span class="code-comment">// 总共需要7次比赛</span>
        <span class="code-keyword">return</span> races;
    }
    
    <span class="code-comment">/**
     * 详细解释赛马问题的解决思路
     */</span>
    <span class="code-keyword">public void</span> explainSolution() {
        System.out.println(<span class="code-string">"赛马问题解决方案:"</span>);
        System.out.println(<span class="code-string">"1. 首先将25匹马分成5组(A,B,C,D,E)，每组5匹马，进行5场比赛"</span>);
        System.out.println(<span class="code-string">"   - 得到每组内部的排名: A1>A2>A3>A4>A5, B1>B2>B3>B4>B5, ..."</span>);
        System.out.println(<span class="code-string">"2. 让各组第一名(A1,B1,C1,D1,E1)比赛一次"</span>);
        System.out.println(<span class="code-string">"   - 假设结果是: A1>B1>C1>D1>E1"</span>);
        System.out.println(<span class="code-string">"3. 分析可知:"</span>);
        System.out.println(<span class="code-string">"   - 第一名肯定是A1"</span>);
        System.out.println(<span class="code-string">"   - 第二名可能是A2或B1"</span>);
        System.out.println(<span class="code-string">"   - 第三名可能是A3,B1,B2或C1"</span>);
        System.out.println(<span class="code-string">"4. 让A2,B1,B2,C1再比赛一次，确定